<script>
lang.class_name = '栏目名称'; 
</script>

<!--添加栏目-->
<div class="dialog_content">
	<form id="info_form" action="{:u('class/add')}" method="post">
	<table width="100%" class="table_form">
		<tr>
			<th width="100">所属模型 :</th>
			<td>
				<select name="module_id" id="module_id">
					<option value="">--请选择--</option>
					{$module_list type='rs'}
					<option value="{$module_list("id")}">{$module_list("title")}</option>
					{/$module_list}
				</select>
			</td>
		</tr>
		<tr>
			<th>栏目名称 :</th>
			<td><input type="text" name="name" id="name" class="input-text" size="30"></td>
		</tr>
		<tr> 
			<th>上级栏目 :</th>
			<td>
				<select class="J_cate_select mr10" data-pid="0" data-uri="" data-selected=""></select>
				<input type="hidden" name="pid" id="J_cate_id" />
			</td>
		</tr>
		<tr>
			<th>栏目类型 :</th>
			<td>
				<label><input type="radio" name="typeid" value="0" checked> 普通分类</label>&nbsp;&nbsp;
                <label><input type="radio" name="typeid" value="1"> 单页面</label>
			</td>
		</tr>
        <tr>
            <th>栏目图片 :</th>
            <td>
            	<input type="text" name="img" id="J_img" class="input-text fl mr10" size="30" rel="">
            	<div id="J_upload_img" class="upload_btn"><span>{:L('upload')}</span></div>
            </td>
        </tr>
        <tr>
		<th>{:L('enabled')} :</th>
            <td>
                <label><input type="radio" name="status" value="1" checked> {:L('yes')}</label>&nbsp;&nbsp;
                <label><input type="radio" name="status" value="0"> {:L('no')}</label>
            </td>
        </tr>
		<tr>
			<th>{:L('seo_title')} :</th>
			<td><input type="text" name="seo_title" id="seo_title" class="input-text" style="width:300px;"></td>
		</tr>
		<tr>
			<th>{:L('seo_keys')} :</th>
			<td><input type="text" name="seo_keys" id="seo_keys" class="input-text" style="width:300px;"></td>
		</tr>
		<tr>
			<th>{:L('seo_desc')} :</th>
			<td><textarea name="seo_desc" style="width:300px; height:50px;"></textarea></td>
		</tr>
	</table>
	</form>
</div>
<script src="__STATIC__/js/fileuploader.js"></script>
<script>
function select_pid() {
	var select = $(".J_cate_select");
	var module_id = 0;
	$.ajax({
		type: "GET",
		url: "{:U('class/ajax_getcatmodid')}",
		data: {id: '{:App.Req("pid")}'},
		dataType: "json",
		async:'false',
		success: function(result){
			module_id = result.data;
			select.attr('data-uri','{:U("class/ajax_getchilds?module_id=")}'+module_id);
			select.attr('data-selected','{$spid}');
			select.cate_select();
			module_select();
		}
	});
}
function module_select() {
	$('.J_cate_select').live('change',function (){
		setTimeout(function(){
			var module_id = 0;
			$.ajax({
				type: "GET",
				url: "{:U('class/ajax_getcatmodid')}",
				data: {id: $('#J_cate_id').val()},
				dataType: "json",
				async:'false',
				success: function(result){
					module_id = result.data;
					$("#module_id").val(module_id);
				}
			});
		},1500);
	});
}
$(function(){

	$("#name").formValidator({onshow:lang.please_input+lang.class_name,onfocus:lang.please_input+lang.class_name}).inputValidator({min:1,onerror:lang.please_input+lang.class_name});
	
	$("#module_id").formValidator({onshow:"请选择内容模型",onfocus:"请选择内容模型"}).inputValidator({min:1,onerror:"请选择内容模型"});

	$('.J_cate_select').html('<option value="">--请选择--</option>');
	{if App.Req("pid")<>""}
		select_pid();
	{/if}

	module_select();

	$('#module_id').live('change',function (){
		var select = $(".J_cate_select");
		var module_id = $(this).val();
		if(module_id!='') {
			select.attr('data-uri','{:U("class/ajax_getchilds?module_id=")}'+module_id);
			select.attr('data-selected','');
			select.cate_select();
			if($('#J_cate_select').val()>0) module_select();
		}
		else {
			$('#J_cate_id').val('');
			$('.J_cate_select').html('<option value="">--请选择--</option>');
		}
	});
	
	//上传图片
    var uploader = new qq.FileUploaderBasic({
    	allowedExtensions: ['jpg','gif','jpeg','png','bmp','pdg'],
        button: document.getElementById('J_upload_img'),
        multiple: false,
        action: "{:U('class/ajax_upload_img')}",
        inputName: 'img',
        forceMultipart: true,
        messages: {
        	typeError: lang.upload_type_error,
        	sizeError: lang.upload_size_error,
        	minSizeError: lang.upload_minsize_error,
        	emptyError: lang.upload_empty_error,
        	noFilesError: lang.upload_nofile_error,
        	onLeave: lang.upload_onLeave
        },
        showMessage: function(message){
        	$.jframe.tip({content:message, icon:'error'});
        },
        onSubmit: function(id, fileName){
        	$('#J_upload_img').addClass('btn_disabled').find('span').text(lang.uploading);
        },
        onComplete: function(id, fileName, result){
        	$('#J_upload_img').removeClass('btn_disabled').find('span').text(lang.upload);
            if(result.status == '1'){
        		$('#J_img').val(result.data);
				$('#J_img').attr('rel',result.data);
        		//$('.J_attachment_icon').empty();
        		//$('.J_attachment_icon').attr('file-rel',result.data);
        	} else {
        		$.jframe.tip({content:result.msg, icon:'error'});
        	}
        }
    });
});
</script>